/*	
 * Authors: Ken YANG <spng.yang@gmail.com>
 * 	
 * Mammoth client main program
 *
 * Copyright (C) 2007-2008 Ken YANG
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation, version 2. 
 * THIS SOFTWARE COMES "AS IS" WITHOUT ANY WARRANTIES.
 */

#include "threads.h"


/* pthread api wrapper */
int Pthread_create(pthread_t *tid, const pthread_attr_t *attr,
		void *(*start_routine)(void *), void *args)
{
	int rc;
	if((rc=pthread_create(tid,attr,start_routine,args))==0)
		return;
	errno=rc;
	err_sys("pthread_create error");
}

void Pthread_detach(pthread_t tid)
{
	int rc;
	if((rc=pthread_detach(tid))==0)
		return;
	errno=rc;
	err_sys("pthread_detach error");
}

void Pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
{
	int rc;
	if((rc=pthread_key_create(key,destructor))==0)
		return;
	errno=rc;
	err_sys("pthread_key_create error");
}

void
Pthread_once(pthread_once_t *ptr, void (*func)(void))
{
	int n;
	if((n = pthread_once(ptr, func)) == 0)
		return;
	errno = n;
	err_sys("pthread_once error");
}

void
Pthread_setspecific(pthread_key_t key, const void *value)
{
        int n;
	if((n=pthread_setspecific(key, value)) == 0)
		return;
	errno = n;
	err_sys("pthread_setspecific error");
}


void Pthread_mutex_lock(pthread_mutex_t *mutex)
{
	int rc;
	if((rc=pthread_mutex_lock(mutex))==0)
		return;
	errno=rc;
	err_sys("pthread_mutex_lock error");
}


void Pthread_mutex_unlock(pthread_mutex_t *mutex)
{
	int rc;
	if((rc=pthread_mutex_unlock(mutex))==0)
		return;
	errno=rc;
	err_sys("pthread_mutex_unlock error");
}

